/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package FormController;

import Service.UserProfileService;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.web.servlet.ModelAndView;
import th.co.tac.esv.pre.ejb.dat.dprompt.chng.password.DpromptChngPasswordResponse;

/**
 *
 * @author Peat
 */
public class UserProfileFormController extends BaseFormController {

    public UserProfileFormController() {
        super("UserProfileController.properties",
                null,
                null);
    }

    protected ModelAndView ChngPassword_Console(
            ModelAndView mv, HttpServletRequest request,
            HttpServletResponse response)
            throws NamingException, JSONException
    {
        UserProfileService service = new UserProfileService();
        JSONObject result = new JSONObject();
        String action = request.getParameter("action");
        if (action.equals("changepassword"))
        {
            DpromptChngPasswordResponse uRes = service.changePassword(request);

            result.put("result", true);
            result.put("errCode", uRes.getErrorCode());
            result.put("errorMsg", uRes.getErrorMessage());
            result.put("errorTuxMsgSqlCode",  uRes.getErrorTuxMsgSqlCode());
            result.put("errorTuxMsgTextEng",  uRes.getErrorTuxMsgTextEng());
            result.put("errorTuxMsgTextThai",  uRes.getErrorTuxMsgTextThai());
            
            mv.addObject("result", result.toString());
        }
        return mv;
    }

    protected ModelAndView GenPassPort_Console(
            ModelAndView mv, HttpServletRequest request,
            HttpServletResponse response)
            throws NamingException, JSONException
    {
        UserProfileService service = new UserProfileService();
        JSONObject result = new JSONObject();
        String action = request.getParameter("action");
        if (action.equals("genpass"))
        {
            

            mv.addObject("result", result.toString());
        }
        return mv;
    }

}
